import cv2
import numpy as np
class ResultEvaluator:
    @staticmethod
    def nc(img1:np.ndarray, img2:np.ndarray):
        """计算nc值"""
        # 将图像转换为浮点型
        img1 = img1.astype(np.float64)
        img2 = img2.astype(np.float64)
        
        # 计算图像的平均值
        mean_img1 = np.mean(img1)
        mean_img2 = np.mean(img2)
        
        # 计算NCC
        numerator = np.sum((img1 - mean_img1) * (img2 - mean_img2))
        denominator = np.sqrt(np.sum((img1 - mean_img1) ** 2) * np.sum((img2 - mean_img2) ** 2))
        
        ncc = numerator / denominator
        
        return ncc
    @staticmethod
    def psnr(img1:np.ndarray, img2:np.ndarray):
        """计算psnr"""
        image1 = np.clip(img1, 0, 255).astype(np.uint8)
        image2 = np.clip(img2, 0, 255).astype(np.uint8)
        
        return cv2.PSNR(image1, image2)
